package cn.com.surker.pages.console;

import cn.com.surker.base.pump.entity.PumpNorm;
import cn.com.surker.base.strength.entity.BaseStrength;
import cn.com.surker.base.strength.service.BaseStrengthLevelDosageService;
import cn.com.surker.base.strength.service.impl.PumpNormServiceImpl;
import cn.com.surker.base.strength.service.impl.StrengthServiceImpl;
import cn.com.surker.base.strength.vo.StrengthLevelDosageVo;
import cn.com.surker.base.system.entity.SysLine;
import cn.com.surker.common.AbstractController;
import cn.com.surker.enums.ICodeDescEnum;
import cn.com.surker.enums.lab.SeasonTypeEnum;
import cn.com.surker.enums.lab.UploadTypeEnum;
import cn.com.surker.enums.material.MaterialBreedTypeEnum;
import cn.com.surker.enums.material.SysMaterialTypeEnum;
import cn.com.surker.enums.production.indent.ProTypeEnum;
import cn.com.surker.lab.service.LabLevelOptimizeService;
import cn.com.surker.lab.vo.LabLevelOptimizeVo;
import cn.com.surker.material.service.MainMaterialService;
import cn.com.surker.oa.entity.OaMaterial;
import cn.com.surker.system.entity.SysOrigin;
import cn.com.surker.system.service.SysLineService;
import cn.com.surker.util.DateUtil;
import cn.com.surker.util.ReportDateUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.*;

/**
 * @Author lucky
 * @create 2024年10月17 10:47
 * @desc 技术配合比转发类
 */
@Slf4j
@Controller
@RequestMapping("/console/lal-level")
public class LalLevelIndexController extends AbstractController {

    @Resource
    private StrengthServiceImpl strengthService;
    @Resource
    private MainMaterialService materialService;
    @Resource
    private LabLevelOptimizeService levelOptimizeService;
    @Resource
    private SysLineService sysLineService;
    @Resource
    private PumpNormServiceImpl pumpNormService;
    @Resource
    private BaseStrengthLevelDosageService dosageService;
//    @Resource
//    private LabExpendUploadService expendUploadService;

    /**
     * 上传施工配合比界面
     * @return
     */
    @RequestMapping("/upload-expend")
    public ModelAndView updateExpend() {
        ModelAndView modelAndView = new ModelAndView();

        List<SysOrigin> orgList = getUserOrgList();
//        CacheUser user = getUser();
        List<Map<String, Object>> materialTypeList = ICodeDescEnum.getEnumDatasV1(SysMaterialTypeEnum.class);
        List<Map<String, Object>> uploadTypeList = ICodeDescEnum.getEnumDatasV1(UploadTypeEnum.class);
        List<Map<String, Object>> proTypeList = ICodeDescEnum.getEnumDatasV1(ProTypeEnum.class);//任务单状态
        Long orgId = -1l;
        if (orgList != null && orgList.size() > 0)
            orgId = orgList.get(0).getId();
        Date nowDate = new Date();
        String startTime = DateUtil.convertString(DateUtil.convertBeforeDayDate(nowDate, 30), "yyyy-MM-dd") + " 08:30:00";
        String endTime = DateUtil.convertString(DateUtil.convertBeforeDayDate(nowDate, -1), "yyyy-MM-dd") + " 08:30:00";
        List<SysLine> lineList = sysLineService.findAll();
//        List<BaseStrength> strengthList = strengthService.findAll();
        List<PumpNorm> normList = pumpNormService.findAll();
        List<OaMaterial> materialList = materialService.findByStorage(orgId);
        List<StrengthLevelDosageVo> dosageList = dosageService.findDosageVo(orgId, null);
        modelAndView.addObject("dosageList", dosageList);
        modelAndView.addObject("startTime", startTime);
        modelAndView.addObject("endTime", endTime);
        modelAndView.addObject("proTypeList", proTypeList);
        modelAndView.addObject("normList", normList);
        modelAndView.addObject("materialList", materialList);
        modelAndView.addObject("lineList", lineList);
        modelAndView.addObject("uploadTypeList", uploadTypeList);
        modelAndView.addObject("materialList", materialList);
//        modelAndView.addObject("strengthList", strengthList);
        modelAndView.addObject("orgList", orgList);
        modelAndView.addObject("materialTypeList", materialTypeList);
        modelAndView.setViewName("console/lab/upload-expend");
        return modelAndView;
    }
    /**
     * 配比监控详情
     * @return
     */
    @RequestMapping("/history-expend-detail")
    public ModelAndView historyExpendDetail(Long indentId) {
        ModelAndView modelAndView = new ModelAndView();

        modelAndView.addObject("indentId", indentId);
        modelAndView.setViewName("console/lab/history-expend-detail");
        return modelAndView;
    }
    /**
     * 配比监控
     * @return
     */
    @RequestMapping("/history-expend")
    public ModelAndView historyExpend() {
        ModelAndView modelAndView = new ModelAndView();

        List<SysOrigin> orgList = getUserOrgList();
//        CacheUser user = getUser();
        List<Map<String, Object>> materialTypeList = ICodeDescEnum.getEnumDatasV1(SysMaterialTypeEnum.class);
        List<Map<String, Object>> uploadTypeList = ICodeDescEnum.getEnumDatasV1(UploadTypeEnum.class);
        List<Map<String, Object>> proTypeList = ICodeDescEnum.getEnumDatasV1(ProTypeEnum.class);//任务单状态
//        Long orgId = -1l;
//        if (orgList != null && orgList.size() > 0)
//            orgId = orgList.get(0).getId();
        Date nowDate = new Date();
        String startTime = DateUtil.convertString(DateUtil.convertBeforeDayDate(nowDate, 30), "yyyy-MM-dd") + " 08:30:00";
        String endTime = DateUtil.convertString(DateUtil.convertBeforeDayDate(nowDate, -1), "yyyy-MM-dd") + " 08:30:00";
        modelAndView.addObject("startTime", startTime);
        modelAndView.addObject("endTime", endTime);
        modelAndView.addObject("proTypeList", proTypeList);
        modelAndView.addObject("uploadTypeList", uploadTypeList);
//        modelAndView.addObject("strengthList", strengthList);
        modelAndView.addObject("orgList", orgList);
        modelAndView.addObject("materialTypeList", materialTypeList);
        modelAndView.setViewName("console/lab/history-expend");
        return modelAndView;
    }
    /**
     * 配比监控
     * @return
     */
    @RequestMapping("/strength-expend")
    public ModelAndView strengthExpend() {
        ModelAndView modelAndView = new ModelAndView();

        List<SysOrigin> orgList = getUserOrgList();
//        CacheUser user = getUser();
        List<Map<String, Object>> materialTypeList = ICodeDescEnum.getEnumDatasV1(MaterialBreedTypeEnum.class);
//        Long orgId = -1l;
//        if (orgList != null && orgList.size() > 0)
//            orgId = orgList.get(0).getId();
        Date nowDate = new Date();
        List<SysLine> lineList = sysLineService.findAll();
        String startTime = ReportDateUtils.getMonthReportStartTime(nowDate);
        String endTime = ReportDateUtils.getMonthReportEndTime(nowDate);
        modelAndView.addObject("startTime", startTime);
        modelAndView.addObject("endTime", endTime);
        modelAndView.addObject("lineList", lineList);
        modelAndView.addObject("orgList", orgList);
        modelAndView.addObject("materialTypeList", materialTypeList);
        modelAndView.setViewName("console/lab/strength-expend");
        return modelAndView;
    }
    /**
     * 施工配合比处理界面
     * @return
     */
    @RequestMapping("/construct")
    public ModelAndView construct() {
        ModelAndView modelAndView = new ModelAndView();

        List<SysOrigin> orgList = getUserOrgList();
//        CacheUser user = getUser();
        List<Map<String, Object>> seasonTypeList = new ArrayList<>();
        List<Map<String, Object>> materialTypeList = new ArrayList<>();
        for (int i = 0; i < SeasonTypeEnum.values().length; i++) {
            Map<String, Object> temp = new HashMap<>();
            temp.put("id", SeasonTypeEnum.values()[i].getCode());
            temp.put("name", SeasonTypeEnum.values()[i].getDescription());
            seasonTypeList.add(temp);
        }
        for (int i = 0; i < SysMaterialTypeEnum.values().length; i++) {
            if (SysMaterialTypeEnum.values()[i].getCode() > 1 && SysMaterialTypeEnum.values()[i].getCode() < 10) {
                Map<String, Object> temp = new HashMap<>();
                temp.put("id", SysMaterialTypeEnum.values()[i].getCode());
                temp.put("name", SysMaterialTypeEnum.values()[i].getDescription());
                materialTypeList.add(temp);
            }
        }

        Long orgId = -1l;
        if (orgList != null && orgList.size() > 0)
            orgId = orgList.get(0).getId();
        List<LabLevelOptimizeVo> levelOptimizeList = levelOptimizeService.findAll();
        List<BaseStrength> strengthList = strengthService.findByOrg(orgId);
        List<OaMaterial> materialList = materialService.findByOrg(orgId);
        List<StrengthLevelDosageVo> dosageList = dosageService.findDosageVo(orgId, null);
        modelAndView.addObject("dosageList", dosageList);
        modelAndView.addObject("levelOptimizeList", levelOptimizeList);
        modelAndView.addObject("materialList", materialList);
        modelAndView.addObject("strengthList", strengthList);
        modelAndView.addObject("orgList", orgList);
        modelAndView.addObject("seasonTypeList", seasonTypeList);
        modelAndView.addObject("materialTypeList", materialTypeList);
        modelAndView.setViewName("console/lab/construct");
        return modelAndView;
    }
    /**
     * 标准配合比处理界面
     * @return
     */
    @RequestMapping("/optimize")
    public ModelAndView optimize() {
        ModelAndView modelAndView = new ModelAndView();

        List<SysOrigin> orgList = getUserOrgList();
//        CacheUser user = getUser();
        List<Map<String, Object>> seasonTypeList = new ArrayList<>();
        List<Map<String, Object>> materialTypeList = new ArrayList<>();
        for (int i = 0; i < SeasonTypeEnum.values().length; i++) {
            Map<String, Object> temp = new HashMap<>();
            temp.put("id", SeasonTypeEnum.values()[i].getCode());
            temp.put("name", SeasonTypeEnum.values()[i].getDescription());
            seasonTypeList.add(temp);
        }
        for (int i = 0; i < SysMaterialTypeEnum.values().length; i++) {
            if (SysMaterialTypeEnum.values()[i].getCode() > 1 && SysMaterialTypeEnum.values()[i].getCode() < 10) {
                Map<String, Object> temp = new HashMap<>();
                temp.put("id", SysMaterialTypeEnum.values()[i].getCode());
                temp.put("name", SysMaterialTypeEnum.values()[i].getDescription());
                materialTypeList.add(temp);
            }
        }

        Long orgId = -1l;
        if (orgList != null && orgList.size() > 0)
            orgId = orgList.get(0).getId();
        List<BaseStrength> strengthList = strengthService.findByOrg(orgId);
        List<OaMaterial> materialList = materialService.findByOrg(orgId);
        List<StrengthLevelDosageVo> dosageList = dosageService.findDosageVo(orgId, null);
        modelAndView.addObject("dosageList", dosageList);
        modelAndView.addObject("materialList", materialList);
        modelAndView.addObject("strengthList", strengthList);
        modelAndView.addObject("orgList", orgList);
        modelAndView.addObject("seasonTypeList", seasonTypeList);
        modelAndView.addObject("materialTypeList", materialTypeList);

        modelAndView.setViewName("console/lab/optimize");
        return modelAndView;
    }

}
